<?php

/**
 * Book
 *
 * @author vbolshov
 */

namespace bs;

use km\db\ActiveRecord;

class Author extends ActiveRecord {
	static protected $table = 'author';
	static protected $defaults = array(
		'name' => null
	);
	static protected $neighbors = array(
		'books' => array('bs\\Book', 'book_author', 'author_id', 'book_id')
	);
	/**
	 * @return Select
	 */
	function getBooks()
	{
		return parent::getNeighbors('books');
	}
	
	protected function _createValidator()
	{
		return parent::_createValidator()
			->addRequired('name', 'name is required')
			->addStringRule('name', 'name should be a string');
	}
}